import { userInfoAPI, userCheckAPI, userModifyAPI } from "@/services/userInfo";
export default {
  namespaced: true,
  state: {
    // ishidden: true,
    userInfo: {},
    data: {},
  },
  mutations: {
    user(state, payload) {
      state.userInfo = payload.data;
      localStorage.setItem("userinfo",JSON.stringify(state.userInfo));
      console.log(JSON.parse(JSON.stringify(state.userInfo)));
    },
    getCheck(state, payload) {
       state.data = { ...payload, time: Date.now() };
    },
    modify(payload) {
      //  if(payload.code==1) {
      //     this.user();
      //  }
      console.log(payload);
    }
  },
  actions: {
    async getUser(context) {
      const res = await userInfoAPI();
      context.commit("user", res);
    },
    async check(context) {
      const resCheck = await userCheckAPI();
      context.commit("getCheck", resCheck);
    },
    async modify(context,payload) {
       const modifyUserinfo = await userModifyAPI(payload);
       context.commit("modify",modifyUserinfo);
      //  console.log(modifyUserinfo);
    }, 
  },
};
